package com.tzbank.fingerPrint.controller;

import com.alipay.api.AlipayApiException;
import com.tzbank.fingerPrint.entity.FingerPrintModel;
import com.tzbank.fingerPrint.service.FingerPrintService;
import com.tzbank.fingerPrint.service.impl.FingerPrintServiceImpl;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api("TZBANK-AI:指纹认证控制器")
@RestController
@Slf4j
public class FingerPrintController {

	@Autowired
	FingerPrintService fingerPrintService;

	/**
	 * 3.2指纹注册初始化 接口:alipay.security.prod.fingerprint.apply.initialize
	 * 
	 * @return
	 * @auther llz&wdj 2018/05/17
	 * @throws AlipayApiException
	 *             业务参数: { "auth_type": "1", "ifaa_version": "2.0" }
	 */
	@ApiOperation(value = "fingerPrintApplyInitialize", notes = "3.2 指纹注册初始化")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "auth_type", value = "auth_type", paramType = "query", required = true),
			@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version", paramType = "query", required = true) })
	@RequestMapping(value = "/fingerPrintApplyInitialize", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> fingerPrintApplyItialize(@RequestBody FingerPrintModel vo) {

		// 判断参数是否为空
		if (StringUtils.isEmpty(vo.getAuth_type()) || StringUtils.isEmpty(vo.getIfaa_version())|| StringUtils.isEmpty(vo.getDeviceId())) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}

		return fingerPrintService.fingerPrintApplyItialize(vo);

	}

	/**
	 * 3.3指纹注册接口 接口:alipay.security.prod.fingerprint.apply
	 * 
	 * @return
	 * @auther llz&wdj 2018/05/17
	 * @throws AlipayApiException
	 *             业务参数: { "ifaf_message": "", //TA 返回的指纹注册消息,json字符 "out_biz_no":
	 *             "20161126200040011100190086557102", "ifaa_version": "2.0" }
	 */
	@ApiOperation(value = "fingerPrintApply", notes = "3.3 指纹注册接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ifaf_message", value = "TA返回的指纹注册消息,json字符", paramType = "query", required = true),
			@ApiImplicitParam(name = "out_biz_no", value = "out_biz_no", paramType = "query", required = true),
			@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version", paramType = "query", required = true),
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", required = true),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query", required = true) })
	@RequestMapping(value = "/fingerPrintApply", method = { RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> fingerPrintApply(@RequestBody FingerPrintModel vo) {
		log.info(vo.toString());
		// 判断参数是否为空
		if (StringUtils.isEmpty(vo.getOut_biz_no()) || StringUtils.isEmpty(vo.getIfaa_version())|| StringUtils.isEmpty(vo.getDeviceId())
				|| StringUtils.isEmpty(vo.getIfaf_message())) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}
		return fingerPrintService.fingerPrintApply(vo);
	}

	/**
	 * 3.4指纹校验初始化接口 接口:alipay.security.prod.fingerprint.verify.initialize
	 * 
	 * @return
	 * @auther llz&wdj 2018/05/17
	 * @throws AlipayApiException
	 *             业务参数: { "token": "96d559c6-cf9b-4b5e-bba7-1e040b4c28c9",
	 *             "ifaa_version": "2.0" }
	 */
	@ApiOperation(value = "FingerPrintVerifyInitialize", notes = "3.4 指纹校验初始化接口")
	@ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "token", paramType = "query", required = true),
			@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version", paramType = "query", required = true),
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", required = true),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query", required = true) })
	@RequestMapping(value = "/fingerPrintVerifyInitialize", method = { RequestMethod.POST })
	public Map<String, Object> fingerPrintVerifyInitialize(@RequestBody FingerPrintModel vo) {

		// 判断参数是否为空
		if (StringUtils.isEmpty(vo.getToken()) || StringUtils.isEmpty(vo.getIfaa_version())||StringUtils.isEmpty(vo.getDeviceId())) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}
		return fingerPrintService.fingerPrintVerifyInitialize(vo);

	}

	/**
	 * 3.5指纹校验接口 接口:alipay.security.prod.fingerprint.verify
	 * 
	 * @return
	 * @auther llz&wdj 2018/05/17
	 * @throws AlipayApiException
	 *             业务参数: { "ifaf_message": "", //TA 校验后的ifaa_message "out_biz_no":
	 *             "20161126200040011100190086557102", "ifaa_version": "2.0",
	 *             "needAuthData": true, "subAction": "update" }
	 */
	@ApiOperation(value = "fingerPrintVerify", notes = "3.5 指纹校验接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ifaf_message", value = "ifaf_message", paramType = "query", required = true),
			@ApiImplicitParam(name = "out_biz_no", value = "out_biz_no", paramType = "query", required = true),
			@ApiImplicitParam(name = "ifaa_version", value = "ifaa_version", paramType = "query", required = true),
			@ApiImplicitParam(name = "needAuthData", value = "needAuthData", paramType = "query", required = true),
			@ApiImplicitParam(name = "subAction", value = "subAction", paramType = "query", required = true),
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", required = true),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query", required = true) })
	@RequestMapping(value = "/fingerPrintVerify", method = { RequestMethod.POST })
	public Map<String, Object> fingerPrintVerify(@RequestBody FingerPrintModel vo) {

		// 判断参数是否为空
	if (StringUtils.isEmpty(vo.getIfaf_message()) || StringUtils.isEmpty(vo.getOut_biz_no())||StringUtils.isEmpty(vo.getDeviceId())
			|| StringUtils.isEmpty(vo.getIfaa_version()) || StringUtils.isEmpty(vo.getSubAction())
			|| StringUtils.isEmpty(String.valueOf(vo.isNeedAuthData()))) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
	}
		return fingerPrintService.fingerPrintVerify(vo);

	}

	/**
	 * 3.6 指纹注销接口 接口:alipay.security.prod.fingerprint.delete
	 * 
	 * @return
	 * @auther llz&wdj 2018/05/17
	 * @throws AlipayApiException
	 *             业务参数: { "token": "96d559c6-cf9b-4b5e-bba7-1e040b4c28c9",
	 *             "ifaa_version": "2.0" }
	 */
	@ApiOperation(value = "fingerPrintDelete", notes = "3.6 指纹注销接口")
	@ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "token信息", paramType = "query", required = true),
			@ApiImplicitParam(name = "ifaa_version", value = "ifaa版本号", paramType = "query", required = true),
			@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", required = true),
			@ApiImplicitParam(name = "requestSource", value = "请求来源", paramType = "query", required = true) })
	@RequestMapping(value = "/fingerPrintDelete", method = { RequestMethod.POST })
	public Map<String, Object> fingerPrintDelete(@RequestBody FingerPrintModel vo) {

		// 判断参数是否为空
		if (StringUtils.isEmpty(vo.getToken()) || StringUtils.isEmpty(vo.getIfaa_version()) || StringUtils.isEmpty(vo.getDeviceId()) ) {
		return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}
		return fingerPrintService.fingerPrintDelete(vo);

	}

}
